package com.fastexport.util;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BaseHandlerUtils {

    public static void setResponse(HttpServletResponse response, String fileName) {
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        if (!(fileName.endsWith(".xlsx") || fileName.endsWith(".xls"))) {
            fileName = fileName + ".xlsx";
        }
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
    }

    public static List<?> getHeadList(List<?> list) {
        return list.isEmpty()
                ? Collections.singletonList(new Object())
                : new ArrayList<>(list.subList(0, 0));
    }

}
